package com.authorization.project.authorization.service.impl;

import java.util.List;

import com.authorization.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.MoudleMicroserviceMappingMapper;
import com.authorization.project.authorization.domain.MoudleMicroserviceMapping;
import com.authorization.project.authorization.service.IMoudleMicroserviceMappingService;

/**
 * 模块-微服务中间Service业务层处理
 * 
 * @author 李晓雷
 * @date 2020-04-23
 */
@Service
public class MoudleMicroserviceMappingServiceImpl implements IMoudleMicroserviceMappingService 
{
    @Autowired
    private MoudleMicroserviceMappingMapper moudleMicroserviceMappingMapper;

    /**
     * 查询模块-微服务中间
     * 
     * @param id 模块-微服务中间ID
     * @return 模块-微服务中间
     */
    @Override
    public MoudleMicroserviceMapping selectMoudleMicroserviceMappingById(Long id)
    {
        return moudleMicroserviceMappingMapper.selectMoudleMicroserviceMappingById(id);
    }

    /**
     * 查询模块-微服务中间列表
     * 
     * @param moudleMicroserviceMapping 模块-微服务中间
     * @return 模块-微服务中间
     */
    @Override
    public List<MoudleMicroserviceMapping> selectMoudleMicroserviceMappingList(MoudleMicroserviceMapping moudleMicroserviceMapping)
    {
        return moudleMicroserviceMappingMapper.selectMoudleMicroserviceMappingList(moudleMicroserviceMapping);
    }

    /**
     * 新增模块-微服务中间
     * 
     * @param moudleMicroserviceMapping 模块-微服务中间
     * @return 结果
     */
    @Override
    public int insertMoudleMicroserviceMapping(MoudleMicroserviceMapping moudleMicroserviceMapping)
    {
        return moudleMicroserviceMappingMapper.insertMoudleMicroserviceMapping(moudleMicroserviceMapping);
    }

    /**
     * 修改模块-微服务中间
     * 
     * @param moudleMicroserviceMapping 模块-微服务中间
     * @return 结果
     */
    @Override
    public int updateMoudleMicroserviceMapping(MoudleMicroserviceMapping moudleMicroserviceMapping)
    {
        return moudleMicroserviceMappingMapper.updateMoudleMicroserviceMapping(moudleMicroserviceMapping);
    }

    /**
     * 批量删除模块-微服务中间
     * 
     * @param ids 需要删除的模块-微服务中间ID
     * @return 结果
     */
    @Override
    public int deleteMoudleMicroserviceMappingByIds(Long[] ids)
    {
        return moudleMicroserviceMappingMapper.deleteMoudleMicroserviceMappingByIds(ids);
    }

    /**
     * 删除模块-微服务中间信息
     * 
     * @param id 模块-微服务中间ID
     * @return 结果
     */
    @Override
    public int deleteMoudleMicroserviceMappingById(Long id)
    {
        return moudleMicroserviceMappingMapper.deleteMoudleMicroserviceMappingById(id);
    }

    /**
     * 批量添加
     * @param moduleId
     * @param serviceIdsList
     */
    @Override
    public void bashInsertMicroservice(Long moduleId, List<Long> serviceIdsList) {
        serviceIdsList.stream().forEach(serviceId -> {
            MoudleMicroserviceMapping moudleMicroserviceMapping = new MoudleMicroserviceMapping();
            moudleMicroserviceMapping.setModuleId(moduleId);
            moudleMicroserviceMapping.setMicroserviceId(serviceId);
            this.insertMoudleMicroserviceMapping(moudleMicroserviceMapping);
        });

    }

    /**
     * 根据模块主键删除
     * @param moduleId
     */
    @Override
    public void deleteMoudleMicroserviceMappingByModuleId(Long moduleId) {
        moudleMicroserviceMappingMapper.deleteMoudleMicroserviceMappingByModuleId(moduleId);
    }

    /**
     * 根据模块主键查询微服务ID集合
     * @param moduleId
     * @return
     */
    @Override
    public List<Long> selectMoudleMicroserviceIdsByModuleId(Long moduleId) {
        return moudleMicroserviceMappingMapper.selectMoudleMicroserviceIdsByModuleId(moduleId);
    }
}
